package com.example.myapplication;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.util.Size;
import android.view.View;
import android.widget.Button;
import android.widget.CompoundButton;
import android.widget.Switch;

import androidx.appcompat.app.AppCompatActivity;

public class ConfigureActivity extends AppCompatActivity {

    private static final String TAG =
            MainActivity.class.getSimpleName();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_configure);

        Button BigSize = findViewById(R.id.BigSize);
        Button MiddleSize = findViewById(R.id.MiddleSize);
        Button SmallSize = findViewById(R.id.SmallSize);

        SharedPreferences ConfigureSp = getSharedPreferences("Configure",MODE_PRIVATE);
        SharedPreferences.Editor edit = ConfigureSp.edit();


        //字体大小按钮
        BigSize.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                edit.putInt("Size",3);
                edit.commit();
            }
        });

        MiddleSize.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                edit.putInt("Size",2);
                edit.commit();
            }
        });

        SmallSize.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                edit.putInt("Size",1);
                edit.commit();
            }
        });


        //switch组件以及监听
        Switch PrintPrice = (Switch) findViewById(R.id.PrintPrice);

        //Log.d(TAG, String.valueOf(ConfigureSp.getBoolean("PrintPrice",false)));
        if(ConfigureSp.getBoolean("PrintPrice",false)){
            PrintPrice.setChecked(true);
        }else{
            PrintPrice.setChecked(false);
        }

        PrintPrice.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
                if(isChecked){
                    edit.putBoolean("PrintPrice",true);
                    edit.commit();
                }else{
                    edit.putBoolean("PrintPrice",false);
                    edit.commit();
                }
            }
        });
    }
}
